package com.appwoo.txtws.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.appwoo.txtws.adapter.BookmarkAdapter;
import com.appwoo.txtws.bean.BookmarkBean;
import com.appwoo.txtws.component.DBHelper;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;

public class BookmarkActivity extends BookActivity
{
  private static Calendar calendar = Calendar.getInstance();

  @SuppressLint({"SimpleDateFormat"})
  private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  private Dialog bookConfirmDialog;
  private Dialog bookDialog;
  private ArrayList<BookmarkBean> bookmarks = new ArrayList();
  private String bookname;
  private View.OnClickListener confirmDialogNoOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookmarkActivity.this.bookConfirmDialog.dismiss();
    }
  };
  private View.OnClickListener confirmDialogRemoveAllYesOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      Iterator localIterator = BookmarkActivity.this.bookmarks.iterator();
      while (true)
      {
        if (!localIterator.hasNext())
        {
          BookmarkActivity.this.getBookmarkList();
          BookmarkActivity.this.bookConfirmDialog.dismiss();
          return;
        }
        BookmarkBean localBookmarkBean = (BookmarkBean)localIterator.next();
        if (localBookmarkBean != null)
          BookmarkActivity.this.mDBHelper.removeBookmarkBean(localBookmarkBean);
      }
    }
  };
  private View.OnClickListener confirmDialogYesOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookmarkBean localBookmarkBean = (BookmarkBean)paramAnonymousView.getTag();
      BookmarkActivity.this.mDBHelper.removeBookmarkBean(localBookmarkBean);
      BookmarkActivity.this.getBookmarkList();
      BookmarkActivity.this.bookConfirmDialog.dismiss();
    }
  };
  private View.OnClickListener dialogCloseOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookmarkActivity.this.bookDialog.dismiss();
    }
  };
  private View.OnClickListener dialogRemoveAllOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookmarkBean localBookmarkBean = (BookmarkBean)paramAnonymousView.getTag();
      BookmarkActivity.this.showConfirmRemoveDialog(localBookmarkBean, false);
    }
  };
  private View.OnClickListener dialogRemoveOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookmarkBean localBookmarkBean = (BookmarkBean)paramAnonymousView.getTag();
      BookmarkActivity.this.showConfirmRemoveDialog(localBookmarkBean, true);
    }
  };
  private View.OnClickListener dialogViewOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookmarkBean localBookmarkBean = (BookmarkBean)paramAnonymousView.getTag();
      Intent localIntent = new Intent(BookmarkActivity.this, BookReaderQuestionActivity.class);
      localIntent.putExtra("bookmarkId", localBookmarkBean.getBookmarkId());
      localIntent.putExtra("readerType", "bookmark");
      BookmarkActivity.this.startActivity(localIntent);
      BookmarkActivity.this.bookDialog.dismiss();
    }
  };
  private DisplayMetrics dm;
  private int firstExtra;
  private LayoutInflater inflater;
  private int listItemHeight;
  private BookmarkAdapter mAdapter;
  private DBHelper mDBHelper;
  private RelativeLayout mLayoutBookmarkHeader;
  private ListView mLvSyncTutorialBookmark;
  private TextView mTvSyncTutorialBookmarkBookname;

  private void findView()
  {
    this.mDBHelper = new DBHelper(this);
    this.mTvSyncTutorialBookmarkBookname = ((TextView)findViewById(2131492969));
    this.mLvSyncTutorialBookmark = ((ListView)findViewById(2131492970));
    this.mLayoutBookmarkHeader = ((RelativeLayout)findViewById(2131492968));
    this.bookname = getIntent().getStringExtra("bookname");
    this.inflater = ((LayoutInflater)getSystemService("layout_inflater"));
  }

  private void getBookmarkList()
  {
    getSyncTutorialBookmarkByBookname(this.bookname);
    while (true)
    {
      if (this.bookmarks.size() >= 5)
      {
        if (this.mAdapter != null)
        {
          this.mAdapter.setData(this.bookmarks);
          this.mAdapter.notifyDataSetChanged();
        }
        return;
      }
      this.bookmarks.add(null);
    }
  }

  private void getListItemHeight()
  {
    getWindow().getWindowManager().getDefaultDisplay().getMetrics(this.dm);
    int i = this.mTvSyncTutorialBookmarkBookname.getHeight();
    int j = this.mLayoutBookmarkHeader.getHeight();
    int k = SyncTutorialActivity.getStatusHeight(this);
    int m = this.dm.heightPixels - i - j - k;
    this.listItemHeight = (m / 5);
    this.firstExtra = (m % 5);
  }

  private void getSyncTutorialBookmarkByBookname(String paramString)
  {
    this.bookmarks = this.mDBHelper.getBookmarkBeanListByBookname(paramString);
  }

  private void setView()
  {
    if ((this.bookname == null) || ("".equals(this.bookname)))
    {
      alertMessage(getString(2131428182));
      finish();
      return;
    }
    this.mTvSyncTutorialBookmarkBookname.setText(this.bookname);
    this.dm = new DisplayMetrics();
    this.mTvSyncTutorialBookmarkBookname.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
      public void onGlobalLayout()
      {
        if (BookmarkActivity.this.mAdapter == null)
        {
          BookmarkActivity.this.getListItemHeight();
          BookmarkActivity.this.mAdapter = new BookmarkAdapter(BookmarkActivity.this, BookmarkActivity.this.bookmarks, BookmarkActivity.this.dm, BookmarkActivity.this.listItemHeight, BookmarkActivity.this.firstExtra);
          BookmarkActivity.this.mLvSyncTutorialBookmark.setAdapter(BookmarkActivity.this.mAdapter);
        }
      }
    });
  }

  public static String timeMillisToString(long paramLong)
  {
    calendar.setTimeInMillis(paramLong);
    return format.format(calendar.getTime());
  }

  protected void backKeyCallBack()
  {
    super.backKeyCallBack();
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903059);
    findView();
    setView();
  }

  protected void onResume()
  {
    super.onResume();
    getBookmarkList();
  }

  public void showConfirmRemoveDialog(BookmarkBean paramBookmarkBean, boolean paramBoolean)
  {
    View localView = this.inflater.inflate(2130903050, null);
    TextView localTextView = (TextView)localView.findViewById(2131492931);
    Button localButton1;
    Button localButton2;
    if (paramBoolean)
    {
      localTextView.setText(getResources().getString(2131428197));
      localButton1 = (Button)localView.findViewById(2131492933);
      localButton2 = (Button)localView.findViewById(2131492934);
      localButton1.setTag(paramBookmarkBean);
      if (!paramBoolean)
        break label187;
      localButton1.setOnClickListener(this.confirmDialogYesOnClickListener);
    }
    while (true)
    {
      localButton2.setOnClickListener(this.confirmDialogNoOnClickListener);
      this.bookConfirmDialog = new Dialog(this, 2131361833);
      this.bookConfirmDialog.addContentView(localView, new LinearLayout.LayoutParams(-2, -2));
      this.bookConfirmDialog.setCanceledOnTouchOutside(true);
      this.bookConfirmDialog.show();
      if ((this.bookDialog != null) && (this.bookDialog.isShowing()))
        this.bookDialog.dismiss();
      return;
      localTextView.setText(getResources().getString(2131428198));
      break;
      label187: localButton1.setOnClickListener(this.confirmDialogRemoveAllYesOnClickListener);
    }
  }

  public void showLongClickDialog(BookmarkBean paramBookmarkBean)
  {
    View localView = this.inflater.inflate(2130903051, null);
    ((ImageView)localView.findViewById(2131492935)).setOnClickListener(this.dialogCloseOnClickListener);
    ((TextView)localView.findViewById(2131492930)).setText(paramBookmarkBean.getUnitname() + " " + paramBookmarkBean.getModulename());
    Button localButton1 = (Button)localView.findViewById(2131492936);
    Button localButton2 = (Button)localView.findViewById(2131492937);
    Button localButton3 = (Button)localView.findViewById(2131492938);
    localButton1.setTag(paramBookmarkBean);
    localButton1.setText(getResources().getString(2131428192));
    localButton1.setOnClickListener(this.dialogViewOnClickListener);
    localButton2.setTag(paramBookmarkBean);
    localButton2.setText(getResources().getString(2131427535));
    localButton2.setOnClickListener(this.dialogRemoveOnClickListener);
    localButton3.setTag(paramBookmarkBean);
    localButton3.setText(getResources().getString(2131428193));
    localButton3.setOnClickListener(this.dialogRemoveAllOnClickListener);
    this.bookDialog = new Dialog(this, 2131361833);
    this.bookDialog.addContentView(localView, new LinearLayout.LayoutParams(-2, -2));
    this.bookDialog.setCanceledOnTouchOutside(true);
    this.bookDialog.show();
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.BookmarkActivity
 * JD-Core Version:    0.6.2
 */